package com.gm.service.user;

import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.github.miemiedev.mybatis.paginator.domain.PageList;
import com.gm.common.Pager;
import com.gm.controller.dto.BillDTO;
import com.gm.dao.bill.IBillDao;
import com.gm.model.po.Bill;
import com.gm.tools.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by Administrator on 2017/6/28.
 */

@Service
public class BillService {

    @Autowired
    private IBillDao billDao;

    public PageList<BillDTO> getBillList(Pager pager){

        PageBounds pageBounds = new PageBounds(pager.getCurrentPage(), pager.getPageSize());
        return billDao.getBillList(pageBounds);
    }

    public List<BillDTO> getAllList(){
        return billDao.getAll();
    }


    public Bill getBillById(Integer id){
        return billDao.selectByPrimaryKey(id);
    }

    public int dealBill(Integer bid){
        Bill bill = billDao.selectByPrimaryKey(bid);
        bill.setStatus(1);//处理过的账单
        bill.setUpdateTime(DateUtils.getCurrentUnixTime());
        return billDao.updateByPrimaryKeySelective(bill);
    }

    public int cancelDealBill(Integer bid){
        Bill bill = billDao.selectByPrimaryKey(bid);
        bill.setStatus(0);//处理过的账单
        bill.setUpdateTime(DateUtils.getCurrentUnixTime());
        return billDao.updateByPrimaryKeySelective(bill);
    }

}
